package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DBUtil {
	static {// 闈欐�佸潡
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			// TODO 鑷姩鐢熸垚鐨� catch 鍧�
			e.printStackTrace();

		}
	}

	private DBUtil() {
	}

	final static String url = "jdbc:mysql://localhost:3306/school?useUnicode=true&characterEncoding=utf8";

	public static Connection getConnection() {
		try {
			return DriverManager.getConnection(url, "root", "123");
		} catch (SQLException e) {
			// TODO 鑷姩鐢熸垚鐨� catch 鍧�
			e.printStackTrace();
		}
		return null;
	}

	public static void closeAll(ResultSet r, Statement s, Connection c) {
		close(r);
		close(s);
		close(c);
	}

	public static void close(ResultSet r) {
		if (r != null)
			try {
				r.close();
			} catch (SQLException e) {
				// TODO 鑷姩鐢熸垚鐨� catch 鍧�
				e.printStackTrace();
			}
	}

	public static void close(Statement r) {
		if (r != null)
			try {
				r.close();
			} catch (SQLException e) {
				// TODO 鑷姩鐢熸垚鐨� catch 鍧�
				e.printStackTrace();
			}
	}

	public static void close(Connection r) {
		if (r != null)
			try {
				r.close();
			} catch (SQLException e) {
				// TODO 鑷姩鐢熸垚鐨� catch 鍧�
				e.printStackTrace();
			}
	}
}
